package org.mobile.api.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import net.sf.json.JSONObject;

import com.ucmed.api.filter.exception.ExecFilterException;
import com.ucmed.api.filter.exec.named.AbsNamedApiExecFilter;

/**
 * 处理智能导诊、可能疾病前台传字符串不统一问题
 * @author Shi
 *
 */
public class DiseaseFifter extends AbsNamedApiExecFilter {
	
	private static final Logger LOG = Logger.getLogger(DiseaseFifter.class);


	private static final String[] API_NAMES = { "Z010006"};

	@Override
	public String[] getApiNames() {
		return API_NAMES;
	}

	@Override
	public void before(JSONObject jsonReq, HttpServletRequest request,
			HttpServletResponse response) throws ExecFilterException {
		try {
			String str = jsonReq.toString();
			str = str.replace("\"[", "[");
			str = str.replace("]\"", "]");
			JSONObject obj =JSONObject.fromObject(str);
			jsonReq.remove("symptom_id_list");
			jsonReq.remove("question_option_id_list");
			jsonReq.put("question_option_id_list", obj.optJSONArray("question_option_id_list"));
			jsonReq.put("symptom_id_list", obj.optJSONArray("symptom_id_list"));
		} catch (Exception e) {
			LOG.error("",e);
		}
	}

}
